<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>测试freemarker</title>
    <link rel="shortcut icon" href="/favicon.ico">
</head>
<body>


<#list ["java","user","apple","an","ans"]?sort as num>
    <h3>${num}</h3>
</#list>
<hr>
<#list [1,10,2,9,0]?sort?reverse as num>
    <h3>${num}</h3>
</#list>
<hr>
<#list 1..10 as n>
    <#if n?is_even_item && n%2 == 0>
        <h3 style="background-color: #f00;">hello - ${n}</h3>
    <#else >
        <h3>hello - ${n}</h3>
    </#if>
    <#if n==6>
        <#break >
    </#if>
</#list>

<#-- map -->
${map.name}${map.id}${map.age}${map.birth?string("yyyy-MM-dd")}
<#assign h = {"name":"mouse", "price":50}>
<#assign keys = h?keys>
<#list keys as key>${key} = ${h[key]}; </#list>

<#list list as i>
    ${i.name}${i.id}${i.age}${i.birth?string("yyyy-MM-dd")} <br>
</#list>

<#--
<#list map?keys as k>
    ${k} = ${map[k]}
</#list>
-->
<hr>
<#--
       ?sort_by()
       ?sort
-->
${stus?first}  == ${stus?last.name}   == ${stus?size}

<#if stus??>
    <#list stus?sort_by("name") as st>
        <h4>id=${st.id},${st.name}---成绩：${st.score}分</h4>
    </#list>
</#if>

<hr>
<!-- html -->
<#-- freemarker 注释 -->

<#list ["java","php","python"] as lang >
    <span>${lang}</span>
</#list>

<#assign  users = ["list1","list2","list3","list50","list4"]>
<#list users![]?reverse as user>
    ${user}
    <#else>
    没有数据
</#list>
<#list 1..5 as num>${num}</#list>
${users?join("-")}
${users?seq_contains("list50")?then("yes","no")}
<hr>



<#--
    布尔不能直接输出
    ${flag?c}
    ${flag?string("yes","no")}
-->
<h3>flag = ${flag?string("yes","no")}</h3>
<#if !flag || true>
    yes
<#else>
    no
</#if>
<h1>默认值</h1>
<#assign address="北京市">
<h3>${address!}</h3>
<h3>${address!"河南省郑州市"}</h3>

<h1>有没有设置值，判断为null</h1>
${(addr??)?c}
<#if addr??>
    ${addr}
<#else>
    没有设置 - <#noparse>${addr}</#noparse>
</#if>
<hr>
<#--
    字符串
-->
<h3>${str} = ${str?length} = ${str?upper_case}  ${str?starts_with("java")?c}</h3>
<#-- 
    日期对象
-->
<h3>${now?date}</h3>
<h3>${now?time}</h3>
<h3>${now?datetime}</h3>
<h3>${now?string("yyyy-MM-dd HH:mm:ss")}</h3>
<h3>${map.birth?date}</h3>
<#--
    数字
-->
<h3>${map.id}</h3>
<h3>${map.age}</h3>
<h3>${money}</h3>
<#assign x = 0.16 aa = 12 num=9.12345>
${x?string.percent}<br>
${x?string["0"]} <br>
${x?string["0.#"]} <br>
${x?string["0.##"]} <br>
${x?string["0.###"]} <br>
${x?string["0.####"]} <br>
<h3>${aa?string("#.###")}  =  ${num?string('0000.00')}</h3>
<#list 1..10 as n>
    <#if n%2 == 0>
        <span style="color:red;">${n?string("000")} &nbsp;</span>
    <#else>
        <span>${n?string("000")} &nbsp;</span>
    </#if>
</#list>

</body>
</html>